<!doctype html>
<html lang="en">
  <head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.4.1/dist/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">

    <title>Hello, world!</title>
    <style>
    video {
        width: 100%;
        height: 360px;
        border: 1px solid gray;
    }
    </style>
  </head>
  <body>
    <div class="container">
        <div class="row">
            <div class="col">
                <video id="videoPlayer" controls></video>
                <div class="input-group">
                <div class="input-group-prepend">
                  <span class="input-group-text">Url</span>
                </div>
                <input type="url" class="form-control" placeholder="http:ip:port/dash/stream.mpd | http:ip:port/hls/stream.m3u8">
                <button id="play" class="btn btn-sm btn-warning ">Go→</button>
              </div>
            </div>
        </div>
    </div>
    <!-- Optional JavaScript -->
    <!-- jQuery first, then Popper.js, then Bootstrap JS -->
    <script src="https://cdn.jsdelivr.net/npm/jquery@3.4.1/dist/jquery.slim.min.js" integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@4.4.1/dist/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script>
    <script src="https://cdn.dashjs.org/latest/dash.all.min.js"></script> 
    <script src="https://cdn.jsdelivr.net/hls.js/latest/hls.min.js"></script>
    <script>
        function dash (url, id) {
            var player = dashjs.MediaPlayer().create();
            player.initialize(document.querySelector('#' + id), url, true);
        }
        function hls (url, id) {
            if(Hls.isSupported()) {
                var video = document.getElementById(id);
                var hls = new Hls();
                hls.loadSource(url);
                hls.attachMedia(video);
                hls.on(Hls.Events.MANIFEST_PARSED,function() {
                  video.play();
                });
            } else {
                console.log('browser not support HLS')
            }
        }
        document.querySelector('#play').addEventListener('click', (event)=>{
            let input_ = event.target.parentNode.querySelector('input')
            let url = input_ !== null ? input_.value : ''
            if (url.length > 0) {
                console.log(url)
                if (url.indexOf('mpd') > 0) {
                    dash(url, 'videoPlayer')
                } else if (url.indexOf('m3u8') > 0) {
                    hls(url, 'videoPlayer')
                }
            }
        })
    </script> 
  </body>
</html>
